package com.woniuxy.couponassembly.dao;

import com.woniuxy.couponassembly.model.UserCoupon;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

/**
 * <p>
 * 用户优惠券关联表 Mapper 接口
 * </p>
 *
 * @author Liyfi
 * @since 2021-05-24
 */
public interface UserCouponMapper extends BaseMapper<UserCoupon> {


    @Select("select * from user_coupon where user_id = #{userId} and coupon_id = #{couponId}")
    List<UserCoupon> findUserCouponByUserId(@Param("userId") int userId,@Param("couponId") int couponId);

    @Delete("delete from user_coupon where user_id = #{userId} and coupon_id = #{couponId}")
    int removeUserCoupon(@Param("userId") int userId,@Param("couponId") int couponId);

    @Select("select * from user_coupon where user_id = #{userId}")
    List<UserCoupon> findUserCouponBuUserId(int userId);

    @Select("select * from user_coupon where user_id = #{user_id} and raw_add_time between 2021-06-05 12:04:17 and 2021-06-05 18:04:17 ")
    List<UserCoupon> findUserCouponByCoupon(@Param("user_id") int userId);

    @Insert("insert into user_coupon (user_id,coupon_id) value(#{userId},#{couponId})")
    int addUserCoupon(@Param("userId") int userId,@Param("couponId") int couponId);

}
